﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Ajeelee.Core.Utils;

namespace AiLuWeb.WebSite.Code
{
    /// <summary>
    /// 知名企业操作类
    /// </summary>
    public class WebSiteConfigManager
    {
        public static string cacheKey = "/Cache/WebSiteConfig/";
        private static object lockHelper = new object();
        public const string configFile = "/Config/WebSiteConfig.config";

        /// <summary>
        /// 获取所有知名企业的信息
        /// </summary>
        /// <returns></returns>
        public static WebSiteConfig GetWebSiteConfig()
        {
            WebSiteConfig topCompanys = new WebSiteConfig();
            if (Function.GetCacheObject(cacheKey) == null)
            {
                lock (lockHelper)
                {
                    if (Function.GetCacheObject(cacheKey) == null)
                    {
                        try
                        {
                            string path = Function.GetMapPath(configFile);
                            topCompanys = path.DeserializeXmlFile(typeof(WebSiteConfig)) as WebSiteConfig;
                            Function.AddCacheObject(cacheKey, topCompanys, DateTime.Now.AddHours(24));
                        }
                        catch (Exception ex)
                        {
                            Function.WriteErrorLog("TopBrand20:");
                            Function.WriteInfoLog(ex);
                        }

                    }
                    else topCompanys = Function.GetCacheObject(cacheKey) as WebSiteConfig;
                }
            }
            else
            {
                topCompanys = Function.GetCacheObject(cacheKey) as WebSiteConfig;
            }

            return topCompanys ?? new WebSiteConfig();
        }
    }
}